package cn.gson.crmdemo.controller.product;



import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.Product;
import cn.gson.crmdemo.model.service.CpService;

@Controller
public class ff {
	@Autowired
	CpService cp;
	
	@RequestMapping("cp")
	@ResponseBody
	public Map<String, Object> cp(Integer page,Integer pageSize) {
		Page<Object> pages = PageHelper.startPage(page,pageSize);
		//当前页的内容
		JSONArray list = cp.selectProduct();
		//总记录数
		long total =  pages.getTotal();
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);
		map.put("total", total);
		return map;
	}

	@RequestMapping("cp-All")
	@ResponseBody
	public Map<String, Object> cpAll() {
		JSONArray list2 = cp.selectSupplier();
		Map<String, Object> map = new HashMap<>();
		map.put("list2", list2);
		return map;
	}
	@RequestMapping("cp-gys")
	@ResponseBody
	public JSONArray cpGys(Integer gysId) {
		return cp.selectSupplierGys(gysId);
	}
	@RequestMapping("add-cp")
	public String addProudct(String cpName,BigDecimal cpPrice,Integer gysId) {
		cp.addProudct(cpName,cpPrice,gysId);
		return "redirect:cp?page=1&pageSize=7";
	}
	//修改
	@RequestMapping("update-cp")
	public String xiug(Integer cpId) {
		System.out.println();
		cp.xg(cpId);
		return "redirect:cp?page=1&pageSize=7";
	}
		
}

